load("@rules_rust//cargo:defs.bzl", "cargo_build_script")
load("@rules_rust//rust:defs.bzl", "rust_library", "rust_test")
load("//bazel:defs.bzl", "rust_test_suite_with_extra_srcs")
load("//bazel:fuzz_testing.bzl", "DEFAULT_RUSTC_FLAGS_FOR_FUZZING")

package(default_visibility = [
    "//rs/http_endpoints:__subpackages__",
    "//rs/pocket_ic_server:__subpackages__",
    "//rs/replica:__subpackages__",
    "//rs/state_machine_tests:__subpackages__",
    "//rs/tests/networking:__subpackages__",
])

DEPENDENCIES = [
    # Keep sorted.
    "//packages/ic-error-types",
    "//rs/config",
    "//rs/crypto/interfaces/sig_verification",
    "//rs/crypto/tls_interfaces",
    "//rs/crypto/tree_hash",
    "//rs/crypto/utils/threshold_sig_der",
    "//rs/http_endpoints/async_utils",
    "//rs/http_endpoints/nns_delegation_manager",
    "//rs/interfaces",
    "//rs/interfaces/registry",
    "//rs/interfaces/state_manager",
    "//rs/limits",
    "//rs/monitoring/logger",
    "//rs/monitoring/metrics",
    "//rs/monitoring/pprof",
    "//rs/monitoring/tracing",
    "//rs/registry/helpers",
    "//rs/registry/provisional_whitelist",
    "//rs/registry/subnet_type",
    "//rs/replicated_state",
    "//rs/types/types",
    "//rs/utils",
    "//rs/validator",
    "@crate_index//:askama",
    "@crate_index//:axum",
    "@crate_index//:byte-unit",
    "@crate_index//:bytes",
    "@crate_index//:cfg-if",
    "@crate_index//:crossbeam",
    "@crate_index//:futures",
    "@crate_index//:futures-util",
    "@crate_index//:hex",
    "@crate_index//:http",
    "@crate_index//:http-body",
    "@crate_index//:http-body-util",
    "@crate_index//:hyper",
    "@crate_index//:hyper-util",
    "@crate_index//:inferno",
    "@crate_index//:mockall",
    "@crate_index//:prometheus",
    "@crate_index//:prost",
    "@crate_index//:rand",
    "@crate_index//:serde",
    "@crate_index//:serde_cbor",
    "@crate_index//:slog",
    "@crate_index//:tempfile",
    "@crate_index//:tokio",
    "@crate_index//:tokio-io-timeout",
    "@crate_index//:tokio-rustls",
    "@crate_index//:tokio-util",
    "@crate_index//:tower",
    "@crate_index//:tower-http",
    "@crate_index//:tracing",
    "@crate_index//:tracing-flame",
    "@crate_index//:tracing-subscriber",
]

MACRO_DEPENDENCIES = [
    # Keep sorted.
    "@crate_index//:async-trait",
]

BUILD_DEPENDENCIES = []

DEV_DEPENDENCIES = [
    # Keep sorted.
    "//rs/canister_client",
    "//rs/canister_client/read_state_response_parser",
    "//rs/canister_client/sender",
    "//rs/canonical_state",
    "//rs/certification/test-utils",
    "//rs/crypto/temp_crypto",
    "//rs/crypto/test_utils/crypto_returning_ok",
    "//rs/crypto/tls_interfaces/mocks",
    "//rs/http_endpoints/test_agent",
    "//rs/interfaces/mocks",
    "//rs/interfaces/registry/mocks",
    "//rs/interfaces/state_manager/mocks",
    "//rs/protobuf",
    "//rs/registry/keys",
    "//rs/registry/routing_table",
    "//rs/test_utilities/consensus",
    "//rs/test_utilities/state",
    "//rs/test_utilities/time",
    "//rs/test_utilities/types",
    "@crate_index//:maplit",
    "@crate_index//:pretty_assertions",
    "@crate_index//:proptest",
    "@crate_index//:reqwest",
    "@crate_index//:rstest",
    "@crate_index//:rustls",
    "@crate_index//:serde_bytes",
    "@crate_index//:tower-test",
]

MACRO_DEV_DEPENDENCIES = []

ALIASES = {}

cargo_build_script(
    name = "build_script",
    srcs = ["build.rs"],
    aliases = ALIASES,
    data = ["templates/dashboard.html"],  # build script data (e.g. template files) goes here
    deps = BUILD_DEPENDENCIES,
)

rust_library(
    name = "public",
    srcs = glob(["src/**"]),
    aliases = ALIASES,
    crate_features = select({
        "//bazel:fuzzing_code_enabled": ["fuzzing_code"],
        "//conditions:default": [],
    }),
    crate_name = "ic_http_endpoints_public",
    proc_macro_deps = MACRO_DEPENDENCIES,
    rustc_flags = select({
        "//bazel:fuzzing_code_enabled": DEFAULT_RUSTC_FLAGS_FOR_FUZZING,
        "//conditions:default": [],
    }),
    version = "0.9.0",
    deps = DEPENDENCIES + [":build_script"],
)

rust_test(
    name = "public_test",
    aliases = ALIASES,
    crate = ":public",
    proc_macro_deps = MACRO_DEPENDENCIES + MACRO_DEV_DEPENDENCIES,
    deps = DEPENDENCIES + DEV_DEPENDENCIES + [":build_script"],
)

rust_test_suite_with_extra_srcs(
    name = "public_integration",
    size = "small",
    srcs = glob(
        ["tests/**"],
        exclude = ["tests/common/**"],
    ),
    extra_srcs = glob(["tests/common/**"]),
    proc_macro_deps = MACRO_DEPENDENCIES + MACRO_DEV_DEPENDENCIES,
    deps = [":public"] + DEPENDENCIES + DEV_DEPENDENCIES,
)
